#!/usr/bin/wish
# vue_fscalq source
# Basic font for button, menus and labels
# Product of NASA/GSFC Geodedic VLBI (2002)
# to be incorporated into the VLBI Field System.
  # Window manager configurations
  set ICONDIR /usr2/fs/fsvue/images
# Use this size of fonts for the information icon, or help.

  global tkVersion
  wm positionfrom . user
  wm sizefrom . ""
  wm maxsize . 1152 900  
  wm iconbitmap . @$ICONDIR/vlb.icon
  wm iconposition . 1200 0
  wm iconname . {fsvue}
#  wm geometry . +5+25
  wm title . {MVC}
  set w .
  $w config -cursor {top_left_arrow black white}

  set bfont {-*-lucida-medium-r-*-sans-18-*-*-*-*-*-*-*}

  proc balloon_help {w msg} {
      bind $w <Enter> "after 1000 \"balloon_aux %W [list $msg]\""
      bind $w <Leave> "after cancel \"balloon_aux %W [list $msg]\"
                        after 100 {catch {destroy .balloon_help}}"
  }

  proc balloon_aux {w msg} {
      set t .balloon_help
      catch {destroy $t}
      toplevel $t
      wm overrideredirect $t 1
      if {$::tcl_platform(platform) == "macintosh"} {
       unsupported1 style $t floating sideTitlebar
      }
      pack [label $t.l -text $msg -relief groove -bd 1 -bg gold] -fill both
      set x [expr [winfo rootx $w]+6+[winfo width $w]/2]
      set y [expr [winfo rooty $w]+6+[winfo height $w]/2]
      wm geometry $t +$x\+$y
      bind $t <Enter> {after cancel {catch {destroy .balloon_help}}}
      bind $t <Leave> "catch {destroy .balloon_help}"
  }

#    pack [button .b -text tryme -command {puts "you did it!"}]
#    balloon_help .b "Text that describes\nwhat the button does"

# Top frame is a menubar
# there is more magic that you can do with this
# build widget .m
frame .m \
        -bg {navy} \
        -borderwidth {2} \
        -relief {groove} 

button .m.help -bitmap @$ICONDIR/info.icon -relief {raise} -font $bfont -background navy -fg white -command {Help logs}

button .m.q -text "Exit" -relief {raise} -font $bfont -background red -fg white -command exit
 
 pack .m.help .m.q -side left -fill both -expand 1
 balloon_help .m.help "click for information"
 balloon_help .m.q "click to Exit this widget"

 entry .e -textvar cmd -font $bfont
 bind .e <Key-Return> {go %W}
 text .t -wrap word -font $bfont -height 10 -width 20 

 proc go {w} {
    global cmd
     .t insert end "Evaluate: $cmd\n"
     .t insert end "========\n"
     set res [exec vueinfo vuecalq $cmd]
     .t insert end $res\n
     .t yview end
     .t insert end "\n\n"
     set cmd ""
 }

 eval pack [winfo children . ] -fill both -expand 1
 focus .e

proc Help {sel} {
        global cmd
# long lines to allow msg to format things

       set h(logs) {Mixed Value Calculations(MVC) 
A calculation can be made by using a mathematical expression. 

Example: (32-18)*36 'or' (#20-18)*'44
would both give you the same answer.
========
504
#1f8
'770
%111111000

Remember that calculation are done left to right. So if you want to isolate a calculation you must use this dilimeters ().
Example:
32-10+2*10 = left to right = 240
32-10+(2*10) = 32-10+20 = 42
32-(10+2)*10 = 32-12+10 = 200
(32-10)+2*10 = 22+2*10 = 240
(32-10+2)*10 = 24*10 = 240
32-(10+2*10) = 32-120 = -88
(32-10)+(2*10) = 22+20 = 42

You also do modulus, xor, and or, and, right/left shift
(mod, xor,|,&,>>,<<).
#10mod3 = 1 
#10|3 = 19
#10&3 = 0
#10xor3 = 19
32-10+2*10mod32 = 16
#10>>2 = 4
#10<<2 = 64

I think you get the idea.

You can mix the base values as shown above or you might just want to know the bit value of #cadd

The answer will be given in:
Decimal         - base 10 -
Hexadecimal     - base 16 -
Octal           - base 8 -
Bits            - base 2 -


It will keep all your calculations. To review all the calculations you've done just click inside the text area and move up and down with the arrow keys.
}

 if { $sel == "commands" } {
   set h(commands) {Key    Alias
 }
 foreach name [lsort [array names cmd]] {
   set h(commands) [format "%s\n%-7s\t%s" $h(commands) $name $cmd($name)]
 }
 }
 tk_dialog .help "Information" $h($sel) {} -1 OK
}
#
# This is a standard bit of code, modified to use my font
# dialog.tcl --
#
# This file defines the procedure tk_dialog, which creates a dialog
# box containing a bitmap, a message, and one or more buttons.
#
# $Header: /user6/ouster/wish/library/RCS/dialog.tcl,v 1.4 93/08/16 16:59:52 ouster Exp $ SPRITE (Berkeley)
#
# Copyright (c) 1992-1993 The Regents of the University of California.
# All.vpeople.rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above cop.vpeople.right notice and the following two paragraphs appear in
# all copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#

#
# tk_dialog:
#
# This procedure displays a dialog box, waits for a button in the dialog
# to be invoked, then returns the index of the selected button.
#
# Arguments:
# w -           Window to use for dialog top-level.
# title -       Title to display in dialog's decorative frame.
# text -        Message to display in dialog.
# bitmap -      Bitmap to display in dialog (empty string means none).
# default -     Index of button that is to display the default ring
#               (-1 means none).
# args -        One or more strings to display in buttons across the
#               bottom of the dialog box.

proc tk_dialog {w title text bitmap default args} {
    global tk_priv

    set bfont {-*-lucida-bold-r-*-sans-12-*-*-*-*-*-*-*}

    set ICONDIR /usr2/fs/fsvue/images
    # 1. Create the top-level window and divide it into top
    # and bottom parts.

    catch {destroy $w}
    toplevel $w -class Dialog
    wm title $w $title
    wm iconbitmap $w @$ICONDIR/vlb.icon
    wm iconname $w {VLBIIE}

    frame $w.top -relief raised -bd 1 -bg blue
    pack $w.top -side top -fill both
    frame $w.bot -relief raised -bd 1 -bg blue
    pack $w.bot -side bottom -fill both

    # 2. Fill the top part with bitmap and message.

    message $w.msg -width 5i -text $text -font $bfont
    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 5m -pady 5m
    if {$bitmap != ""} {
        label $w.bitmap -bitmap $bitmap
        pack $w.bitmap -in $w.top -side left -padx 5m -pady 5m
    }

    # 3. Create a row of buttons at the bottom of the dialog.

    set i 0
    foreach but $args {
        button $w.button$i -text $but -command "set tk_priv(button) $i"
        if {$i == $default} {
            frame $w.default -relief sunken -bd 1 -bg blue
            raise $w.button$i $w.default
            pack $w.default -in $w.bot -side left -expand 1 -padx 3m -pady 2m
            pack $w.button$i -in $w.default -padx 2m -pady 2m \
                    -ipadx 2m -ipady 1m
            bind $w <Return> "$w.button$i flash; set tk_priv(button) $i"
        } else {
            pack $w.button$i -in $w.bot -side left -expand 1 \
                    -padx 3m -pady 3m -ipadx 2m -ipady 1m 
        }
        incr i
    }

    # 4. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    wm withdraw $w
    update idletasks
    set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
            - [winfo vrootx [winfo parent $w]]]
    set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
            - [winfo vrooty [winfo parent $w]]]
    wm geom $w +$x+$y
    wm deiconify $w

    # 5. Set a grab and claim the focus too.

#    set oldFocus [focus]
#    grab $w
#    focus $w

    # 6. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.

    tkwait variable tk_priv(button)
    destroy $w
#    focus $oldFocus
    return $tk_priv(button)
}
